﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH.DB_Map.ywxt
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    using DB_NH.DB_Model.ywxt;

    public class t_sys_user_Map : ClassMapping<t_sys_user>
    {
        public t_sys_user_Map()
        {
            //映射ID
            Id(x => x.user_id, map => map.Length(40));

            Property(x => x.is_valid);
            Property(x => x.create_date);

            Property(x => x.user_domain, map => map.Length(200));
            Property(x => x.sp_mail, map => map.Length(200));
            Property(x => x.user_email, map => map.Length(200));
            Property(x => x.user_loginname, map => map.Length(50));
            Property(x => x.user_truename_cn, map => map.Length(50));
            Property(x => x.user_truename_en, map => map.Length(50));
            Property(x => x.user_roles, map => map.Length(10000));
            Property(x => x.user_code, map => map.Length(10));
            Property(x => x.user_password, map => map.Length(50));

            //员工联系电话
            Property(x => x.user_desktopphone, map => map.Length(50));
            Property(x => x.user_fax, map => map.Length(50));
            Property(x => x.user_mobilephone, map => map.Length(50));

            //项目所属部门
            ManyToOne(x => x.department, map =>
            {
                map.Column(t_sys_user.Columns.dept_id);
                map.NotNullable(false);
            });

            //用户发起的审核记录列表
            Bag(x => x.MyApprovalReocords, map =>
            {
                map.Key(km => km.Column("UserId"));
            }, act => act.OneToMany());

            //用户操作的审核节点列表
            Bag(x => x.MyApprovalNodes, map =>
            {
                map.Key(km => km.Column("UserId"));
            }, act => act.OneToMany());

            //用户操作的待办记录列表（多对多）
            Bag(x => x.MyApprovalToDos, map =>
            {
                //map.Table("ref_User_ToDo");
                map.Table("ref_ToDo_User");
                map.Key(keyMapper => keyMapper.Column("UserId"));
            }, act => act.ManyToMany(m => m.Column("ToDoId")));

            //用户流程审批角色列表（多对多）
            Bag(x => x.MyApprovalUserRoles, map =>
            {
                map.Table("ref_User_ToDoRoles");
                map.Key(keyMapper => keyMapper.Column("UserId"));
            }, act => act.ManyToMany(m => m.Column("ToDoRoleId")));

            Table(t_sys_user.TableName);

            //不进行创建
            SchemaAction(NHibernate.Mapping.ByCode.SchemaAction.None);
        }
    }
}
